﻿using System.Data.Entity;
using System.Runtime.Remoting.Messaging;

namespace OASystem.DAL
{
    public class DbContextFactory<TS> where TS : DbContext, new()
    {
        public static DbContext GetCurrentDbContext()
        {
            var dbContext = CallContext.GetData(typeof(TS).Name) as DbContext;
            if (dbContext != null)
            {
                return dbContext;
            }
            else
            {
                dbContext = new TS();
                CallContext.SetData(typeof(TS).Name, dbContext);
                return dbContext;
            }
        }
    }

}
